

include $(TOPDIR)/rules.mk

PKG_NAME:=web_cgi
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk


define Package/web_cgi
  SECTION:=net
  CATEGORY:=Base system
  TITLE:=cgi program for web interface
  DEPENDS:=+libxml2 +libuci +libiw
endef

define Package/web_cgi/description
  cgi program for web interface
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include
TARGET_CFLAGS += -I$(STAGING_DIR)/usr/include/libxml2
TARGET_LDFLAGS += -L$(STAGING_DIR)/usr/lib

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
	CC="$(TARGET_CC)" \
	CFLAGS="$(TARGET_CFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	all
endef

define Package/web_cgi/install
	$(INSTALL_DIR) $(1)/usr/mips
	$(INSTALL_DIR) $(1)/usr/mips/cgi-bin
#	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DIR) $(1)/usr/mips/cgi-bin/script
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/* $(1)/usr/mips/cgi-bin
	$(CP) $(PKG_BUILD_DIR)/script/* $(1)/usr/mips/cgi-bin/script
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/cfg $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/nor $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/check_stm8 $(1)/bin
#	$(CP) ./src/testuart $(1)/etc/init.d/testuart
#	$(CP) $(PKG_BUILD_DIR)/bin/test_uart $(1)/bin/test_uart
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/led_control_reload $(1)/bin/led_control_reload
endef

$(eval $(call BuildPackage,web_cgi))
